(function(jQuery) {
	/*
	 * 所有DC查询放大镜JS插件
	 */

	var gridColMenu_Detail = null;

	$.MagnifierALLDCUtils = {
		/**
		 * 页面初始化函数
		 */
		init : function() {
			var name = encodeURI($('#condition').val());
			// 创建列表DataGrid
			$('#magnifierALLDCPage_alldc')
					.datagrid(
							{
								url : 'magnifier/getMagnifierALLDCList.do?catch='
										+ new Date()
										+ '&name='
										+ name
										+ '&Login_SessionId=' 
										+ sessionId,
								method : 'get',
								title : $.i18n.prop("js.magnifier.title.allDC"),
								iconCls : 'icon-large-smartart',
								pagination : true,
								rownumbers : true,
								striped : true,
								pageSize : 10,
								pageList : [10],
								columns : [ [ {
									field : 'ck',
									checkbox : true
								}, {
									field : 'id',
									title : $.i18n.prop("js.magnifier.datagrid.id"),
									hidden : true,
									width : 0,
									align : 'left'
								}, {
									field : 'code',
									title : $.i18n.prop("js.magnifier.datagrid.code"),
									width : 170,
									align : 'left'
								}, {
									field : 'name',
									title : $.i18n.prop("js.magnifier.datagrid.name"),

									width : 235,
									align : 'left'
								} ] ],

								onDblClickRow : function(rowIndex, rowData) {
									//向父页面赋值
									if ($('#magnifierALLDCPage_id').val() != null && $('#magnifierALLDCPage_id').val().length > 0) {
										$("#" + $('#magnifierALLDCPage_id').val()).val(rowData.id);
									}
									if ($('#magnifierALLDCPage_code').val() != null && $('#magnifierALLDCPage_code').val().length > 0) {
										$("#" + $('#magnifierALLDCPage_code').val()).val(rowData.code);
									}
									if ($('#magnifierALLDCPage_name').val() != null && $('#magnifierALLDCPage_name').val().length > 0) {
										$("#" + $('#magnifierALLDCPage_name').val(),
												window.parent.document).searchbox(
												'setValue', rowData.name);
									}
									//关闭放大镜窗口
									$("#magnifier_window").window('close');
								},
								onLoadError: function(){
									$.LmisUtils.opLoadError();
								}
							});
		},

		/**
		 * 查询
		 */
		search : function() {
			var name = encodeURI($('#condition').val());
			$('#magnifierALLDCPage_alldc')
					.datagrid(
							{
								url : 'magnifier/getMagnifierALLDCList.do?catch='
										+ new Date()
										+ '&name='
										+ name
										+ '&Login_SessionId=' 
										+ sessionId
							});
		},
		
		/**
		 * 确定
		 */
		ok : function() {
			var selectedDCs = $('#magnifierALLDCPage_alldc').datagrid(
					'getSelections');
			var id = "";
			var code = "";
			var name = "";
			var index = 0;
			for (index = 0; index < selectedDCs.length; index++) {
				if (index == 0) {
					id = id + selectedDCs[index].id;
					code = code + selectedDCs[index].code;
					name = name + selectedDCs[index].name;
				} else {
					id = id + "," + selectedDCs[index].id;
					code = code + "," + selectedDCs[index].code;
					name = name + "," + selectedDCs[index].name;
				}
			}
			//向父页面赋值
			if ($('#magnifierALLDCPage_id').val() != null && $('#magnifierALLDCPage_id').val().length > 0) {
				$("#" + $('#magnifierALLDCPage_id').val()).val(id);
			}
			if ($('#magnifierALLDCPage_code').val() != null && $('#magnifierALLDCPage_code').val().length > 0) {
				$("#" + $('#magnifierALLDCPage_code').val()).val(code);
			}
			if ($('#magnifierALLDCPage_name').val() != null && $('#magnifierALLDCPage_name').val().length > 0) {
				$("#" + $('#magnifierALLDCPage_name').val(),
						window.parent.document).searchbox(
						'setValue', name);
			}
			//关闭放大镜窗口
			$("#magnifier_window").window('close');
		}
	};
})(jQuery);
$.MagnifierALLDCUtils.init();
